﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Lavka.Core;
using Lavka.Models;

namespace Lavka.Controllers
{
    public class SearchController : Controller
    {
        private LavkaDbEntities context = new LavkaDbEntities();

        public JsonResult GetReferences(string query)
        {
            return Json(ProductsHelper.GetProductReferences(query, context));
        }

        public JsonResult GetByString(string query)
        {
            return Json(ProductsHelper.GetByString(query, context));
        }

        public JsonResult GetNames(string query)
        {
            return Json(ProductsHelper.GetProductNames(query, context));
        }
        public ViewResult Find(string SearchReference, string SearchName, string PriceFrom, string PriceTo, string cbSets, string BrandId)
        {
            bool bSets = !string.IsNullOrEmpty(cbSets);
            List<Products> result = SearchHelper.FindProducts(SearchReference, SearchName, PriceFrom, PriceTo, bSets, BrandId, context);
            return View("SearchResults", result);
        }
    }
}
